Page({
    data: {
        lilist: '',
        lilist2: '',
    },
    onLoad: function (options) {
        // 这里的 name："home" 就是在 package.json中定义的名称
        // let that = this;
        wx.cloud.callFunction({
            name: 'home',
            // config: {
            //   env: 'cloud1-0gynot18c71f42a8'
            // },
            data: {
                type: 'share'
            }
        }).then((resp) => {
            console.log(resp.result);
            this.randomlist(resp.result.data);

        }).catch((e) => {
            console.log(e);

        });
    },
    randomlist: function (arr) {
        let arry1 = [];
        arry1 = arr.map(item => {
            return { name: item.name, userimg: item.userimg, phone: item.phone }
        })
        let arry2 = arr.map(item => {
            return item.issue
        })
        let arry3 = []
        for (var i = 0; i < arry1.length; i++) {
            for (var j = 0; j < arry2.length; j++) {
                for (var k = 0; k < arry2[j].length; k++) {
                    if (arry1[i].phone == arry2[j][k].phone) {
                        arry2[j][k].name = arry1[i].name;
                        arry2[j][k].userimg = arry1[i].userimg;
                    }
                }
            }
        }
        for (var z = 0; z < arry2.length; z++) {
            arry3 = arry3.concat(arry2[z])

        }
        let arry4 = arry3.slice(0);
        let temp;
        for (let n = 0; n < arry4.length / 2; n++) {
            temp = arry4[n];
            arry4[n] = arry4[arry4.length - 1 - n];
            arry4[arry4.length - 1 - n] = temp;
        }
        // console.log(arry1);
        // console.log(arry2);
        console.log(arry3);
        console.log(arry4);
        this.setData({
            lilist: arry3,
            lilist2: arry4
        })
    },
    //跳转到具体文章
    urlnew:function(event){
        // console.log(event);
        let id = event.currentTarget.dataset.id
        console.log(id);
        wx.navigateTo({
            url: '/mypages/news/news?titid='+id,
            //   events: events,
            success: (result) => { },
            fail: (res) => { },
            complete: (res) => { },
        })
    },
    //跳转到搜索界面
    urlsearch:function(){
        wx.switchTab({
          url: '/mypages/search/search',
        })
    }
})